package librus.control
{
	import flash.filesystem.File;
	
	import librus.model.Card;

	public class CardFinder
	{
		public function CardFinder()
		{
		}
		
		private static const PICTURES:Array = ["png","jpg","jpeg","gif"];
		
		public function getCards(files:Array):Array
		{
			var result:Array = [];
			
			findPictures(files,result);
			
			return result;			
		}
		
		private function findPictures(files:Array, list:Array):void
		{
			for (var i:int=0;i< files.length;i++)
			{
				var file:File = files[i] as File;
				
				if (file.isDirectory)
					findPictures(file.getDirectoryListing(),list);
				else if (isPicture(file))
					list.push(new Card(file));
			}
		}
		
		private function isPicture(file:File):Boolean
		{
			if (!file)
				return false;
			return PICTURES.indexOf(file.name.split(".").pop()) != -1;
		}
	}
}